package com.chuanyang.driverh.mainorder.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.responseresult.WaybillDetailsData;
import com.chuanyang.driverh.utils.StringUtil;

import java.util.List;

public class WayBillPassPointAdapter extends BaseAdapter {
    private boolean isExpand;
    private List<WaybillDetailsData.PassPointsBean> list;
    private Context context;
    private ViewHolder holder;

    public WayBillPassPointAdapter(Context context, List<WaybillDetailsData.PassPointsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
//        if(list.size()<=3)
//        {
//            return  list.size();
//        }
//        else
// {
//            if(isExpand)//表示显示全部途经点
//            {
//                return  list.size();
//            }
//            else {
//                return  3;
//            }
//        }
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.order_item_varpalace, null);
            holder = new ViewHolder();
            holder.iv_varpalace_icon = (ImageView) convertView.findViewById(R.id.iv_varpalace_icon);
            holder.tv_varpalace_start = (TextView) convertView.findViewById(R.id.tv_varpalace_start);
            holder.tv_oredrinfo_city = (TextView) convertView.findViewById(R.id.tv_oredrinfo_city);
            holder.tv_oredrinfo_area = (TextView) convertView.findViewById(R.id.tv_oredrinfo_area);
            holder.tv_orderinfo_contactname = (TextView) convertView.findViewById(R.id.tv_orderinfo_contactname);
            holder.tv_orderinfo_contactphone = (TextView) convertView.findViewById(R.id.tv_orderinfo_contactphone);
            holder.ll_varpalace_contactdiv = (LinearLayout) convertView.findViewById(R.id.ll_varpalace_contactdiv);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        WaybillDetailsData.PassPointsBean bean = list.get(position);
        holder.tv_oredrinfo_city.setText(StringUtil.getRemoveCity(bean.getProvince(), bean.getCity(), bean.getRegions()));
        holder.tv_oredrinfo_area.setText(StringUtil.getRemoveAdd(bean.getProvince(), bean.getCity(), bean.getRegions(), bean.getAddress()));

        if (bean.getPointType().equals("s")) {
            holder.iv_varpalace_icon.setImageResource(R.mipmap.address0);
            holder.tv_varpalace_start.setText("起点");
            holder.ll_varpalace_contactdiv.setVisibility(View.VISIBLE);
            holder.tv_orderinfo_contactname.setText(bean.getContactPerson());
            holder.tv_orderinfo_contactphone.setText(bean.getContactPhone());

        } else if (bean.getPointType().equals("e")) {
            holder.iv_varpalace_icon.setImageResource(R.mipmap.address2);
            holder.tv_varpalace_start.setText("终点");
            holder.ll_varpalace_contactdiv.setVisibility(View.VISIBLE);
            holder.tv_orderinfo_contactname.setText(bean.getContactPerson());
            holder.tv_orderinfo_contactphone.setText(bean.getContactPhone());
        } else {
            holder.iv_varpalace_icon.setImageResource(R.mipmap.address1);
            holder.tv_varpalace_start.setText("途径");
            holder.ll_varpalace_contactdiv.setVisibility(View.GONE);

        }


        return convertView;
    }

    class ViewHolder {
        ImageView iv_varpalace_icon;
        TextView tv_varpalace_start;//起点  或者终点
        TextView tv_oredrinfo_city;
        TextView tv_oredrinfo_area;
        TextView tv_orderinfo_contactname;
        TextView tv_orderinfo_contactphone;
        LinearLayout ll_varpalace_contactdiv;
    }
}
